/**
 * 
 */
package com.net.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.net.domain.Staff;

/**
 * @author Dinesh
 *
 */
public class StaffDao {
final static Logger log = Logger.getLogger(StaffDao.class);
	
	private SqlMapClient sqlMapClient;
	
	@SuppressWarnings("unchecked")
	public List<Staff> getAllStaff () {
		List<Staff> list = null;
		
		try {
			list = (List<Staff>)sqlMapClient.queryForList("getStaff");
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Staff details" + e.getMessage(), e);
		}
		
		return list;		
	}
	
	public Staff getStaff(int referenceId) {
		Staff staff = null;
		
		try {
			staff = (Staff)sqlMapClient.queryForObject("getStaff", referenceId);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Staff details" + e.getMessage(), e);
		}
		
		return staff;
	}


	public boolean updateInfo(Staff staff) {
		int status = 0;
		
		try {
			log.info("Writing the object " + staff.toString());
			status = sqlMapClient.update("updateStaffInfo", staff);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Staff details" + e.getMessage(), e);
		}
		
		return (status != 0);
	}
	
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	@Autowired
	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}


}
